<?php

vendor('csv');

$file = '';
if (count($list->rows)) {
	$rows = array();

	$row = array();
	if (Auth::o()->is('admin')) {
	   $row[] = __d($po_domain, 'client', true);
	}
	$row[] = __d($po_domain, 'income', true);
	$row[] = __d($po_domain, 'outcome', true);

	$rows[] = $row;

    foreach ($list->rows as $item) {
    	$row = array();
    	if (Auth::o()->is('admin')) {
            $row[] = (!empty($item['Client']['name'])) ? $item['Client']['name'] : "—";
    	}
		$row[] = (!empty($item[0]['income'])) ? $item[0]['income'] : "—";
		$row[] = (!empty($item[0]['outcome'])) ? $item[0]['outcome'] : "—";

        $rows[] = $row;
    }
    if (Auth::o()->is('admin') && !empty($total)) {
        $row = array();
        $row[] = __d(null, 'Total', true).':';
        $row[] = (!empty($total['income'])) ? $total['income'] : "—";
        $row[] = (!empty($total['outcome'])) ? $total['outcome'] : "—";

        $rows[] = $row;
    }

    foreach ($rows as $row) {
        $file .= csv::drawLine($row);
    }
}

header("Content-Length: ".strlen($file));

echo $file;

?>